//
//  GHUserManger.m
//  GodHorses
//
//  Created by Mac on 2017/11/14.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "GHUserManger.h"
#define currentUser @"currentUser"
#define GH_USER_TOKEN @"GH_USER_TOKEN"
#define GH_USERID     @"GH_USERID"
@implementation GHUserManger
+ (GHUserManger *)defult{
    static GHUserManger * deflut = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        deflut = [GHUserManger new];
    });
    return deflut;
}
- (GHUserModel*)getCurrentUser{
   NSDictionary *dic =  [[NSUserDefaults standardUserDefaults] valueForKey:currentUser];
   GHUserModel * user = [GHUserModel mj_objectWithKeyValues:dic];
    if ([dic.allKeys containsObject:@"id"]) {
        user.userID = dic[@"id"];
    }
    if (user.token.length > 0) {
        return user;
    }
    return [GHUserModel new];
}
- (NSString *)token{
    NSString * token = [[NSUserDefaults standardUserDefaults] valueForKey:GH_USER_TOKEN];
    return token;
}
- (NSString *)userID{
    NSString * token = [[NSUserDefaults standardUserDefaults] valueForKey:GH_USERID];
    return token;
}
- (void)updateToken:(NSString *)token{
    if (token.length) {
        [[NSUserDefaults standardUserDefaults] setValue:token forKey:GH_USER_TOKEN];
    }else{
        NSLog(@"GH_USER_TOKEN 不能为空");
    }
}
- (void)updateUserID:(NSString *)userID{
    if (userID.length) {
        [[NSUserDefaults standardUserDefaults] setValue:userID forKey:GH_USERID];
    }else{
        NSLog(@"GH_USERID 不能为空");
    }
}
- (void)removeUserPreferce{
     [[NSUserDefaults standardUserDefaults] removeObjectForKey:GH_USER_TOKEN];
     [[NSUserDefaults standardUserDefaults] removeObjectForKey:GH_USERID];
}
- (void)removeToken{
   
}
@end
